﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KouDai.Core.Engine;
using KouDai.Core.Parser;
using KouDai.Core.Models;
using System.Threading;

namespace KouDai.Core.Service
{
    public class KouDaiService
    {
        public static async Task<BackData> GetHotImageWall(string domainName, long minTimeStamp)
        {
            //发送数据
            Dictionary<string, object> body = new Dictionary<string, object>();
            body.Add("domainName", domainName);
            body.Add("minTimeStamp", 0);
            if (minTimeStamp == 0)
            {
                body.Add("maxTimeStamp", long.MaxValue);
            }
            else
            {
                body.Add("maxTimeStamp", minTimeStamp);
            }
            body.Add("limit", 30);
            SendData sendData = new SendData(Constants.QueryRecommend, SendMethod.GET, EncryptType.NONE, null, body);
            //解析器
            KouDaiParser parser = new KouDaiParser();
            HoneyParser honeyParser = new HoneyParser();
            honeyParser.NextParser = parser;
            //接受数据
            List<HoneyEntity> hopeData = new List<HoneyEntity>();
            BackData backData = new BackData(hopeData);
            //通信数据
            CommunicationData commnunicationData = new CommunicationData();
            commnunicationData.SendData = sendData;
            commnunicationData.Parser = honeyParser;
            commnunicationData.BackData = backData;

            NetEngine netEngine = new NetEngine();
            await netEngine.RequestAsync(commnunicationData);
            return backData;
        }
    }
}
